<?php

namespace App\Service;

use App\Invoice;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;

class ExcelExport implements FromArray,WithEvents
{
    protected $invoices;

    public function __construct(array $invoices)
    {
        $this->invoices = $invoices;
    }

    public function array(): array
    {
        return $this->invoices;
    }

    public function registerEvents(): array
    {
        // TODO: Implement registerEvents() method.
        return [
            AfterSheet::class=>function(AfterSheet $event){
                //$event->sheet->getDelegate()->getStyle()
                $i = 65;
                for($i=65;$i<65+18;$i++)
                $event->sheet->getDelegate()->getColumnDimension(chr($i))->setWidth(15);
            }
        ];
    }
}
